﻿using System.Web.Mvc;
using System.Web.Routing;

namespace DTweet
{
    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute("login", "login", new {controller = "Home", action = "account"});
            routes.MapRoute("logout", "logout", new { controller = "Home", action = "logout" });
            routes.MapRoute("loginRequest", "loginRequest", new { controller = "Home", action = "Login" });

            routes.MapRoute("GetForEdit", "GetForEdit/{id}", new { controller = "Home", action = "GetForEdit" });
            routes.MapRoute("SubmitChanges", "SubmitChanges", new { controller = "Home", action = "SubmitChanges" });
            routes.MapRoute("InOrOutFromCircle", "InOrOutFromCircle/{circleName}/{userToken}", new { controller = "Home", action = "InOrOutFromCircle" });

            routes.MapRoute("CreateCircle", "CreateCircle/{circleName}/{userToken}", new { controller = "Home", action = "CreateCircle" });
            routes.MapRoute("ValidatecircleOrUser", "ValidatecircleOrUser/{value}", new { controller = "Home", action = "ValidatecircleOrUser" });

            routes.MapRoute("NewTweet", "NewTweet", new { controller = "Home", action = "Tweet" });

            routes.MapRoute("DeletePost", "DeletePost/{id}", new { controller = "Home", action = "DeletePost" });
            routes.MapRoute("AboutUs", "About-Muaz-Khan", new { controller = "Home", action = "AboutUs" });
            routes.MapRoute("HomePage", "HomePage", new { controller = "Home", action = "HomePage" });
            routes.MapRoute("UsersList", "UsersList", new { controller = "Home", action = "UsersList" });
            routes.MapRoute("AccountSettings", "AccountSettings", new { controller = "Home", action = "AccountSettings" });

            routes.MapRoute("CreateAccount", "CreateAccount", new { controller = "Home", action = "CreateAccount" });
            routes.MapRoute("Circles", "Circles", new { controller = "Home", action = "Circles" });

            routes.MapRoute("DeleteAccountPermanently", "DeleteAccountPermanently", new { controller = "Home", action = "DeleteAccountPermanently" });

            routes.MapRoute("RemoveUserFromCircle", "RemoveUserFromCircle", new { controller = "Home", action = "RemoveUserFromCircle" });
            routes.MapRoute("DeleteCircle", "DeleteCircle", new { controller = "Home", action = "DeleteCircle" });

            routes.MapRoute("GetFollowingOrFollowers", "GetFollowingOrFollowers", new { controller = "Home", action = "GetFollowingOrFollowers" });

            routes.MapRoute("GetMembersFromCircle", "GetMembersFromCircle/{circleToken}", new { controller = "Home", action = "GetMembersFromCircle" });
            routes.MapRoute("UpdateCircleName", "UpdateCircleName/{circleToken}/{circleName}", new { controller = "Home", action = "UpdateCircleName" });

            routes.MapRoute("SaveAccountSettings", "SaveAccountSettings", new { controller = "Home", action = "SaveAccountSettings" });

            routes.MapRoute("RSS", "RSS/{userToken}", new { controller = "Home", action = "RSS" });
            
            routes.MapRoute("status", "{tweetToken}/{postTitle}", new { controller = "Home", action = "Status" });

            routes.MapRoute("user", "{userToken}", new { controller = "Home", action = "UserPage" });

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Homepage", id = UrlParameter.Optional } // Parameter defaults
            );

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}